﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "ActionInstant.h"

namespace SkyEngine2d
{
	
	ActionInstant::ActionInstant()
		:ActionTime(0)
	{
	
	}
	
	ActionInstant::~ActionInstant()
	{
	
	}
	
	bool ActionInstant::isDone() const
	{
		return this->m_isDone;
	}
	
	
	bool ActionInstant::startWithTarget(IActableObject* target)
	{
		if (!ActionTime::startWithTarget(target))
		{
			return false;
		}
	
		m_isDone = false;
		
		return true;
	}
	
	bool ActionInstant::setActionTarget(IActableObject* obj)
	{
		m_target = obj;
		return true;
	}
	
	void ActionInstant::step(float dt)
	{
		float update_dt = 1; //因为时立即执行完毕的动画 so 只需要执行一次update  执行的 进度为 1 
		this->update(update_dt);
	}
	
	void ActionInstant::update(float ratio)
	{
		//只要执行过  动画即为结束 
		m_isDone = true;
	
		this->execute();
	}
	
	ActionCallFunctionSharedPtr ActionCallFunction::create(const std::function<void()>& func)
	{
		auto p = ActionCallFunctionUniquePtr(new ActionCallFunction());
		p->m_callFunc = func;
		return p;
	}
	
	void ActionCallFunction::execute()
	{
		if (m_callFunc)
		{
			m_callFunc();
		}
	}
}
